package com.ws.generation.util;

import com.ws.common.base.entity.Columns;
import com.ws.common.util.StringUtils;
import com.ws.generation.entity.GenerationConfig;

import java.util.List;

public class GenerationUtils {

    public static void setDefaultConfig(GenerationConfig config){

        String tableName=config.getId();
        //包地址
        config.setPackageDir(config.getPackageName().replaceAll("\\.", "/"));
        config.setTableName(tableName);
        config.setJavaName(config.getJavaTableName());
        config.setLowerJavaName(StringUtils.camelMin(tableName));
        config.setLatestName(tableName.split("_")[tableName.split("_").length-1]);
        config.setControllerDir(config.getControllerDirPre());
    }

    public static void setDefaultColumns( List<Columns> columns){

        //字段名处理
        for(Columns column:columns){
            column.setUpperName(StringUtils.camelMax(column.getColumnName()));
            column.setLowerName(StringUtils.camelMin(column.getColumnName()));
            if(column.getDataType().equals("varchar") || column.getDataType().equals("text")){
                column.setStringFilter(" and "+StringUtils.camelMin(column.getColumnName()) + " != ''");
            }
        }
    }
}
